<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<script src="/webjars/jquery/jquery.min.js "></script>
<link href="/css/style.css" rel="stylesheet" type="text/css">
<body class="login">
<div class="login_m">
    <!--	<div class="login_logo"><img src="images/logo.png" width="196" height="46"></div>-->
    <div class="login_logo">
        <h1>财务管理系统</h1>
    </div>
    <div class="login_boder">
        <div class="login_padding">
            <h2>用户名</h2>
            <label>
                <input type="text" id="name" class="txt_input txt_input2" onfocus="if (value ==&#39;Your name&#39;){value =&#39;&#39;}" onblur="if (value ==&#39;&#39;){value=&#39;Your name&#39;}" value="用户名">
            </label>
            <h2>密码</h2>
            <label>
                <input type="password" name="textfield2" id="pwd" class="txt_input" onfocus="if (value ==&#39;******&#39;){value =&#39;&#39;}" onblur="if (value ==&#39;&#39;){value=&#39;******&#39;}" value="请输入密码">
            </label>
<!--            <p class="forgot"><a href="javascript:void(0);">忘记密码?</a></p>-->
            <div class="rem_sub">
<!--                <div class="rem_sub_l">-->
<!--                    <input type="checkbox" name="checkbox" id="save_me">-->
<!--                    <label for="checkbox">记住</label>-->
<!--                </div>-->
                <label>
                    <input type="submit" class="sub_button" name="button" id="button" value="登录" style="opacity: 0.7;">
                </label>
            </div>
        </div>
    </div><!--login_boder end-->
</div><!--login_m end-->

<br />
<br />

<!--<p align="center"> More Templates <a href="http://www.cssmoban.com/cssthemes/" target="_blank" title="模板之家">模板之家</a> - Collect from <a href="http://www.cssmoban.com/cssthemes/" title="网页模板" target="_blank">网页模板</a></p>-->

</body>
<script>
    $("#button").click(
        function (){
        $.ajax({
            url: 'login',
            type: 'post',
            data: {"name":$("#name").val(),"pwd":$("#pwd").val()},
            success: function (res)
            {
                //请求令牌
                queryToken($("#name").val(),$("#pwd").val());
            },
            error: function (res)
            {
                alert("用户名或密码错误")
             }
        })
    })

    //请求令牌
    function queryToken(name,pwd)
    {
        $.ajax({
           url:'authentication' ,
            type:'post',
            data:{"name":name,"pwd":pwd}
            ,success: function (res)
            {
                //将token放入localstorage中
                localStorage.wrnm=res.data
                location.assign("index.html");
            },
            error:function (res)
            {
                 alert("用户名或密码错误")
            }
        });
    }
</script>
</html>